package com.cw.jeeyt.service.directive;

import java.io.Writer;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cw.jeeyt.common.utils.DateUtils;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateModel;

/**
 * 页脚自定义标签
 *
* @author chenw
* @version 1.0.0
 */
public class FooterDirective implements TemplateDirectiveModel {
    private static final Logger logger = LoggerFactory.getLogger(FooterDirective.class);
    private String companyName = "chenw.com";

    @SuppressWarnings("rawtypes")
    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) {
        Writer out = env.getOut();
        env.setOutputEncoding("utf-8");
        try {
            TemplateModel company = (TemplateModel) params.get("company");
            if (company != null) {
                companyName = company.toString();
            }
            String year = DateUtils.getYear();
            StringBuilder sb = new StringBuilder();
            sb.append("<div class=\"footer\">");
            sb.append("	<div class=\"footer-inner\">");
            sb.append("		<div class=\"footer-content\" style=\"height:30px;background-color:#fbfbfb;\">");
            sb.append("			<span class=\"bigger-110\">技术支持 :</span>");
            sb.append("			<span class=\"bigger-110\" id=\"support_springblade\">" + companyName + "</span>");
            sb.append("			<span class=\"bigger-110\"  style=\"padding-left:15px;\">");
            sb.append("				© " + year);
            sb.append("			</span>");
            sb.append("		</div>");
            sb.append("	</div>");
            sb.append("</div>");
            sb.append("<a href=\"#\" id=\"btn-scroll-up\" class=\"btn-scroll-up btn btn-sm btn-inverse\">");
            sb.append(" <i class=\"ace-icon fa fa-angle-double-up icon-only bigger-110\">");
            sb.append("  顶部");
            sb.append(" </i>");
            sb.append("</a>");
            out.write(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("底部信息加载出错：{}", e.getMessage());
        }
    }

}
